package jFreeChart;

import java.awt.Color;
import java.awt.Font;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

public class ChartFactory
{

	public static void main(String[] args)
	{
		// barChartDemo();
		barChart3DDemo();
		// pieChart3DDemo();
		// pieChartDemo();
		lineChartDemo();
	}

	public static void barChartDemo()
	{
		DefaultCategoryDataset dataset = ChartHelper.getDatasetOfCategory();
		dataset.addValue(100, "北京", "满意");
		dataset.addValue(100, "上海", "满意");
		dataset.addValue(100, "广州", "满意");
		dataset.addValue(100, "pan", "满意");
		dataset.addValue(300, "北京", "非常满意");
		dataset.addValue(300, "上海", "非常满意");
		dataset.addValue(300, "广州", "非常满意");
		dataset.addValue(300, "pan", "非常满意");
		dataset.addValue(400, "北京", "一般");
		dataset.addValue(400, "上海", "一般");
		dataset.addValue(400, "广州", "一般");
		dataset.addValue(400, "pan", "一般");
		dataset.addValue(500, "北京", "不满意");
		dataset.addValue(500, "上海", "不满意");
		dataset.addValue(500, "广州", "不满意");
		dataset.addValue(500, "pan", "不满意");
		JFreeChart chart = ChartHelper.createBarChart$DefaultFont("客户评价结果", "评价类型", "评价人数", dataset, PlotOrientation.VERTICAL, true, true, true);

		ChartHelper.showChartFrame("客户评价结果图", chart, false);
	}

	public static void barChart3DDemo()
	{
		DefaultCategoryDataset dataset = ChartHelper.getDatasetOfCategory();
		dataset.addValue(100, "北京", "满意");
		dataset.addValue(100, "上海", "满意");
		dataset.addValue(100, "广州", "满意");
		dataset.addValue(100, "pan", "满意");
		dataset.addValue(300, "北京", "非常满意");
		dataset.addValue(300, "上海", "非常满意");
		dataset.addValue(300, "广州", "非常满意");
		dataset.addValue(300, "pan", "非常满意");
		dataset.addValue(400, "北京", "一般");
		dataset.addValue(400, "上海", "一般");
		dataset.addValue(400, "广州", "一般");
		dataset.addValue(400, "pan", "一般");
		dataset.addValue(500, "北京", "不满意");
		dataset.addValue(500, "上海", "不满意");
		dataset.addValue(500, "广州", "不满意");
		dataset.addValue(500, "pan", "不满意");
		JFreeChart chart = ChartHelper.createBarChart3D$DefaultFont("客户评价结果", "评价类型", "评价人数", dataset, PlotOrientation.VERTICAL, true, true, true);

		ChartHelper.showChartFrame("客户评价结果图", chart, false);
	}

	public static void pieChartDemo()
	{
		DefaultPieDataset dataset = ChartHelper.getDatasetOfPie();
		dataset.setValue("个人业务", new Double(10));
		dataset.setValue("vip业务", new Double(15));
		dataset.setValue("缴费业务", new Double(10));
		dataset.setValue("买票业务", new Double(10));

		JFreeChart chart = ChartHelper.createPieChart("分类项目业务量占比", dataset, true, true, true);
		PiePlot plot = (PiePlot) chart.getPlot();
		// 图片中显示百分比:默认方式
		// plot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
		// 图片中显示百分比:自定义方式，{0} 表示选项， {1} 表示数值， {2} 表示所占比例 ,小数点后两位
		plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
		// 图例显示百分比:自定义方式， {0} 表示选项， {1} 表示数值， {2} 表示所占比例
		plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
		// 指定图片的透明度(0.0-1.0)
		plot.setForegroundAlpha(1.0f);
		// 指定显示的饼图上圆形(false)还椭圆形(true)
		plot.setCircular(true);

		// 设置背景色为白色
		chart.setBackgroundPaint(Color.white);
		// 设置图标题的字体
		Font font = new Font("黑体", Font.CENTER_BASELINE, 20);
		TextTitle title = new TextTitle("分类项目业务量占比");
		title.setFont(font);
		chart.setTitle(title);

		ChartHelper.setFontPiePlotDefault(chart);
		ChartHelper.showChartFrame("分类项目业务量占比图", chart, true);
	}

	public static void pieChart3DDemo()
	{
		DefaultPieDataset dataset = ChartHelper.getDatasetOfPie();
		dataset.setValue("个人业务", new Double(10));
		dataset.setValue("vip业务", new Double(15));
		dataset.setValue("缴费业务", new Double(10));
		dataset.setValue("买票业务", new Double(10));

		JFreeChart chart = ChartHelper.createPieChart3D("分类项目业务量占比", dataset, true, true, true);
		PiePlot3D plot = (PiePlot3D) chart.getPlot();
		// 图片中显示百分比:默认方式
		// plot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
		// 图片中显示百分比:自定义方式，{0} 表示选项， {1} 表示数值， {2} 表示所占比例 ,小数点后两位
		plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
		// 图例显示百分比:自定义方式， {0} 表示选项， {1} 表示数值， {2} 表示所占比例
		plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
		// 指定图片的透明度(0.0-1.0)
		plot.setForegroundAlpha(1.0f);
		// 指定显示的饼图上圆形(false)还椭圆形(true)
		plot.setCircular(true);

		// 设置背景色为白色
		chart.setBackgroundPaint(Color.white);
		// 设置图标题的字体
		Font font = new Font("黑体", Font.CENTER_BASELINE, 20);
		TextTitle title = new TextTitle("分类项目业务量占比");
		title.setFont(font);
		chart.setTitle(title);

		ChartHelper.setFontPiePlotDefault(chart);
		ChartHelper.showChartFrame("分类项目业务量占比图", chart, true);

	}

	public static void lineChartDemo()
	{
		String[] rowKeys = { "个人业务", "vip业务", "缴费业务" };
		String[] colKeys = { "2011-03-02", "2011-03-03", "2011-03-04", "2011-03-05", "2011-03-06" };

		double[][] data = { { 50, 20, 30, 20, 32 }, { 20, 10D, 40D, 10, 14 }, { 40, 30.0008D, 38.24D, 42, 26 }, };

		CategoryDataset dataset = ChartHelper.getCategoryDatasetOfLine(rowKeys, colKeys, data);

		JFreeChart chart = ChartHelper.createLineChart3D("客户流量分析 ", "日期", "业务类型", dataset, PlotOrientation.VERTICAL, true, true, true);
		ChartHelper.setFontBarChartDefault(chart);

		ChartHelper.showChartFrame("客户流量折线图", chart, true);
	}

}
